import React, { useDebugValue, useEffect, useState } from 'react'

export default function useClientWidth() {
  //声明一个状态
  let [width, setWidth] = useState(window.document.documentElement.clientWidth);
  //调试某个数据
  // useDebugValue(width);
  useEffect(() => {
    //当浏览器的视口大小发生改变的时候, 自动触发
    window.onresize = function(){
      setWidth(window.document.documentElement.clientWidth)
    }
  }, []);
  return width;
}
